#include "widget.h"
#include "ui_widget.h"
#include "mylabel.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //鼠标移动操作选项
    //this->setMouseTracking(true);
    //开启定时器事件,timerId定时器ID
    timerId=this->startTimer(1000);

}

Widget::~Widget()
{
    delete ui;
}

void Widget::mouseMoveEvent(QMouseEvent *event)
{
    QString str=QString("鼠标松开事件：x = %1，y = %2").arg(event->globalX()).arg(event->globalY());
    ui->label_2->setText(str);
}

void Widget::wheelEvent(QWheelEvent *event)
{
    qDebug()<<event->delta();
}

void Widget::keyPressEvent(QKeyEvent *event)
{
    if((event->key()==Qt::Key_A) && (event->modifiers()==Qt::ControlModifier))
    {
        ui->label->setText("CTRL+A");
        qDebug()<<"CTRL+A";
        return;
    }
    switch(event->key())
    {
    case Qt::Key_A:
        ui->label->setText("A");
        qDebug()<<"A";
        break;
    case Qt::Key_B:
        ui->label->setText("B");
        qDebug()<<"B";
        break;
    case Qt::Key_C:
        ui->label->setText("C");
        qDebug()<<"C";
        break;
    case Qt::Key_D:
        ui->label->setText("D");
        qDebug()<<"D";
        break;
    case Qt::Key_E:
        ui->label->setText("E");
        qDebug()<<"E";
        break;
    case Qt::Key_F:
        ui->label->setText("F");
        qDebug()<<"F";
        break;
    case Qt::Key_G:
        ui->label->setText("G");
        qDebug()<<"G";
        break;
    case Qt::Key_H:
        ui->label->setText("H");
        qDebug()<<"H";
        break;
    case Qt::Key_I:
        ui->label->setText("I");
        qDebug()<<"I";
        break;
    default:
        ui->label->setText("other");
        qDebug()<<"other";
        break;
    }
}

void Widget::timerEvent(QTimerEvent *event)
{
    //判断定时器是哪个触发的
    //所有定时器都会触发这个事件
    if(event->timerId()==timerId)
    {
        int value = ui->lcdNumber->value();
        if(value<=0)
        {
            this->killTimer(timerId);
            return;
        }
        ui->lcdNumber->display(value-1);
    }
}

void Widget::moveEvent(QMoveEvent *event)
{
    qDebug()<<event->pos();
}

void Widget::resizeEvent(QResizeEvent *event)
{
    qDebug()<<event->size();
}



